package easy;

public class Solution_LCP_22 {

    public int paintingPlan(int n, int k) {
        if (k < n) {
            return 0;
        } else if (k == 0 || k == n * n) {
            return 1;
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            int a = 1, b = 1;
            for (int p = 1; p <= i; p++) {
                a *= (n - p + 1);
                b *= p;
            }
            for (int j = 0; j < n; j++) {
                if (i * n + j * n - i * j == k) {
                    int aa = 1, bb = 1;
                    for (int p = 1; p <= j; p++) {
                        aa *= (n - p + 1);
                        bb *= p;
                    }
                    count += (a / b * aa / bb);
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_LCP_22 model = new Solution_LCP_22();
        System.out.println(model.paintingPlan(2, 2));
        System.out.println(model.paintingPlan(2, 1));
        System.out.println(model.paintingPlan(2, 4));
    }
}
